package com.telecom.weixi.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.telecom.weixi.R;

public class SearchBlockView extends LinearLayout {

	private ClickAbleText title;
	private TextView subTitle1;
	private TextView subTitle2;
	private TextView subTitle3;
	private TextView contentTitle;
	private TextView content11;
	private TextView content12;
	private TextView latn_name;

	public interface OnBlockTitleListenner {
		void onBlockTitleClick(int pos);
	}

	public SearchBlockView(Context context) {
		this(context, null);
	}

	public SearchBlockView(Context context, AttributeSet attrs) {
		super(context, attrs);
		setupView(context);
	}

	int blockRowNum;

	public void setRowNum(int num) {
		blockRowNum = num;
	}

	OnBlockTitleListenner titleListener;

	public void setTitleClickListener(OnBlockTitleListenner l) {
		titleListener = l;
	}

	public void setTitleClickAble(boolean isAbled) {
		title.setClickAble(isAbled);
	}

	public void setTitle(String value) {
		title.setText(value);
	}

	public void setSubTitle1(String value) {
		subTitle1.setText(value);
	}

	public void setSubTitle2(String value) {
		subTitle2.setText(value);
	}

	public void setSubTitle3(String value) {
		subTitle3.setText(value);
	}

	public void setContentTitle(String value) {
		contentTitle.setText(value);
	}

	LayoutParams lp;
	LinearLayout mContainer;

	void setupView(Context context) {
		LayoutInflater flater = LayoutInflater.from(context);
		flater.inflate(R.layout.layout_block, this);

		mContainer = (LinearLayout) findViewById(R.id.block_container);

		title = (ClickAbleText) findViewById(R.id.title_content);
		subTitle1 = (TextView) findViewById(R.id.subtitle1);
		subTitle2 = (TextView) findViewById(R.id.subtitle2);
		subTitle3 = (TextView) findViewById(R.id.subtitle3);

		contentTitle = (TextView) findViewById(R.id.content_title);
		content11 = (TextView) findViewById(R.id.content11);
		content12 = (TextView) findViewById(R.id.content12);

		latn_name = (TextView) findViewById(R.id.latn_name);

		lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

		this.setOnClickListener(titleClickListener);
	}

	View.OnClickListener titleClickListener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			if (titleListener != null) {
				titleListener.onBlockTitleClick(blockRowNum);
			}
		}
	};

	public SearchBlockView initTitle(String title0, String title1, String title2, String title3) {
		title.setText(title0);
		subTitle1.setText(title1);
		subTitle2.setText(title2);
		subTitle3.setText(title3);
		return this;
	}

	public SearchBlockView initLatn_name(String latn_name) {
		this.latn_name.setText(latn_name);
		return this;
	}

	public SearchBlockView init1Row(String title, String content1, String content2) {
		contentTitle.setText(title);
		content11.setText(content1);
		content12.setText(content2);
		return this;
	}

	public SearchBlockView addSingleRow(String content1, boolean isSingleLine) {
		Block1LineRowView lineRow = new Block1LineRowView(getContext());
		lineRow.initContent(content1, isSingleLine);
		mContainer.addView(lineRow, lp);
		return this;
	}

	public SearchBlockView add2Row(String content1, String content2) {
		BlockRowView blockRow = new BlockRowView(getContext());
		blockRow.initContent(content1, content2);
		mContainer.addView(blockRow, lp);
		return this;
	}

}
